var MixlyCssLoader = {};

/**
 * 加载 link 文件
 * @param href
 */
MixlyCssLoader.loadCss = function (href) {
    var addSign = true;
    var links = document.getElementsByTagName("link");
    for (var i = 0; i < links.length; i++) {
        if (links[i] && links[i].href && links[i].href.indexOf(href) != -1) {
            addSign = false;
        }
    }
    if (addSign) {
        var $link = document.createElement("link");
        $link.setAttribute("rel", "stylesheet");
        $link.setAttribute("type", "text/css");
        $link.setAttribute("href", href);
        document.getElementsByTagName("head").item(0).appendChild($link);
    }
}

/**
 * 删除 link 文件
 * @param href
 */
MixlyCssLoader.removeCss = function (href) {
    var links = document.getElementsByTagName("link");
    for (var i = 0; i < links.length; i++) {
        var _href = links[i].href;
        if (links[i] && links[i].href && links[i].href.indexOf(href) != -1) {
            links[i].parentNode.removeChild(links[i]);
        }
    }
}

/* 公共css */
MixlyCssLoader.commonCss = [
    //"common/css/ACEfont.css",
    //"common/css/fontello.css",
    //"common/css/nav.css",
    //"common/css/library.css"
];

/* 客户端css */
MixlyCssLoader.clientCss = [

];

/* 网页端css */
MixlyCssLoader.webCss = [

];

MixlyCssLoader.load = function () {
    var filePath = MixlyUrl.BOARD_CONFIG?.thirdPartyBoard ? "../../" : "../";

    function loadCssArr(arr) {
        for (let i = 0; i < arr.length; i++) {
            MixlyCssLoader.loadCss(filePath + arr[i]);
        }
    }

    loadCssArr(MixlyCssLoader.commonCss);

    if (MixlyEnv.isClient) {
        loadCssArr(MixlyCssLoader.clientCss);
    } else {
        loadCssArr(MixlyCssLoader.webCss);
    }
}

MixlyCssLoader.load();